﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

namespace HHHFramework
{
    public class LevelManager
    {
        private static List<string> mLevelNames;

        public static int Index { get; set; }

        public static void Init(List<string> levelNames)
        {
            mLevelNames = levelNames;

            Index = 0;
        }

        public static void LoadCurrent()
        {
            SceneManager.LoadScene(mLevelNames[Index]);
        }

        public static void LoadNext(UnityAction<Scene, LoadSceneMode> SceneLoadedManager)
        {
            Index++;

            if (Index >= mLevelNames.Count)
            {
                Index = 0;
            }

            LoadScene(SceneLoadedManager);
        }
       


        private static void LoadScene(UnityAction<Scene, LoadSceneMode> SceneLoadedManager)
        {
            SceneManager.LoadScene(mLevelNames[Index]);
            SceneManager.sceneLoaded += SceneLoadedManager;
        }

        //未完成  等待加入新的内容
        public static void AsyncLoadNext(UnityAction<Scene, LoadSceneMode> SceneLoadedManager)
        {
            Index++;

            if (Index >= mLevelNames.Count)
            {
                Index = 0;
            }

            LoadSceneAsync(SceneLoadedManager);
        }

        private static void LoadSceneAsync(UnityAction<Scene, LoadSceneMode> SceneLoadedManager)
        {

            SceneManager.LoadSceneAsync(mLevelNames[Index]);
            SceneManager.sceneLoaded += SceneLoadedManager;
        }


    }
}